<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>转换为数值类型</title>
</head>

<body>
    <img src="images/4.jpg" alt="" width="380" style="float:left;padding-top: 78px;" />
    <img src="images/3.jpg" alt="" width="600" />
    <script>
    //隐式转换为数值类型最简单的方法就是  *1
    console.log(false * 1); //0
    console.log(true * 1); //1
    console.log(undefined * 1); //NaN
    console.log(null * 1); //0
    console.log("" * 1); //0
    console.log(" " * 1); //0
    console.log("123" * 1); //123
    console.log("123abc" * 1); //NaN
    console.log("1a2b3c" * 1); //NaN
    //强制转换
    var str = "123.5abc";//true false  "1a2b3c" null undefined
    console.log(parseInt(str));
    console.log(parseFloat(str));
    console.log(Number(str));
    </script>
</body>

</html>